package com.yswee.mallnavi.view.coupon.hor;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import com.yswee.framework.utils.ViewInject;
import com.yswee.framework.widget.layoutview.MRelativeLayout;
import com.yswee.mallnavi.R;
import com.yswee.mallnavi.entity.info.CouponEntity;
import com.yswee.mallnavi.view.coupon.IListView;
import com.yswee.mallnavi.view.coupon.list.ListItem;


public class HListItem extends MRelativeLayout<CouponEntity> {

	@ViewInject
	private ListItem lstitem0;
	@ViewInject
	private ListItem lstitem1;

	private IListView.IActionCallback mActionCallback;

	public void setActionCallback(IListView.IActionCallback c) {
		mActionCallback = c;
	}

	public HListItem(Context context) {
		super(context);
	}

	public HListItem(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected int getLayoutResId() {
		return R.layout.view_info_coupon_hlistitem;
	}
	
	@Override
	protected void onBindListener() {
		super.onBindListener();
		IListView.IActionCallback callback = new IListView.IActionCallback() {
			@Override
			public void onInfoClicked(View v, CouponEntity coupon) {
				if (coupon == null) {
					return;
				}
				if (mActionCallback != null) {
					mActionCallback.onInfoClicked(v, coupon);
				}
			}
		};
		lstitem0.setActionCallback(callback);
		lstitem1.setActionCallback(callback);
	}

	@Override
	protected void onApplyData() {
		lstitem0.setDataSource(mDataItem);
		if (mDataItem.bottom != null) {
			lstitem1.setDataSource(mDataItem.bottom);
			lstitem1.setVisibility(View.VISIBLE);
		} else {
			lstitem1.setVisibility(View.INVISIBLE);
		}
	}

}
